export const serializer = {
  deserialize: (str) => {
    let state = JSON.parse(str, (key, value) => {
      if (key === 'component') {
        let componentFn = new Function('return ' + value)();
        return componentFn;
      } else if (typeof value === 'string' && value.includes('-FUNCTION')) {
        return new Function('return ' + value.replace('-FUNCTION', ''))();
      } else {
        return value;
      }
    });
    return state;
  },
  serialize: (state) => {
    const stateStr = JSON.stringify(state, (key, value) => {
      if (key === 'component') {
        return value + '';
      } else if (typeof value === 'function') {
        return value + '-FUNCTION';
      } else {
        return value;
      }
    });
    return stateStr;
  },
};
